package com.example.mp.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mp.entity.TabStudent;
import com.example.mp.service.ITabStudentService;
import com.example.mp.util.Result;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zf
 * @since 2023-02-02
 */
@RestController
@CrossOrigin
@RequestMapping("/tab-student")
public class TabStudentController {
    @Resource
    private ITabStudentService tabStudentService;
        @GetMapping("getAll")
            public Result getAll(){
                List<TabStudent> list = tabStudentService.list();
                return new Result(list);
            }
        @GetMapping("getAllPage")
    public Result getAllPage(Integer curr,Integer size,String province, String name){
            Page page = new Page(curr,size);
            QueryWrapper queryWrapper = new QueryWrapper();
            if(StringUtils.isNotBlank(province)){
                queryWrapper.eq("province",province);
            }
            if(StringUtils.isNotBlank(name)){
                queryWrapper.like("name",name);
            }
            Page list = tabStudentService.page(page,queryWrapper);
            return  new Result(list);
        }
        @DeleteMapping("delStu/{id}")
    public Result delStu(@PathVariable Integer id){
            System.out.println("id="+id);
            boolean b = tabStudentService.removeById(id);
            return new Result(b);
        }
        @PostMapping("addstu")
    public Result addStu(TabStudent student){
        System.out.println("student = " +student);
        boolean b = tabStudentService.saveOrUpdate(student);
        return new Result(b);
    }

}

